package com.bf.utils;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池工具类
 */
@Setter
@Slf4j
public abstract class BfThreadPoolCommon {
    // 任务名称
    protected String jobName;
    // 线程池
    protected ThreadPoolExecutor threadPoolExecutor = null;
    // 线程池名称
    protected String threadPoolName = "BfThreadPool";

    /**
     * 运行方法（必须要执行此方法才能运行）
     *
     * @return
     */
    public void initialize() {
        threadPoolExecutor = SpringUtils.getBean(threadPoolName);
        String id = String.valueOf(IdUtil.getSnowflake().nextId());
        this.jobName = StrUtil.isEmpty(jobName) ? id : jobName + ":" + id;
    }

}
